#pragma once
#include <iostream>
#include <assert.h>
#include <string.h>
namespace refrain
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		string(const char* str = "")
			:_size(strlen(str))
		{
			_str = new char[_size + 1];
			_capacity = _size;
			memcpy(_str, str, _size + 1);
		}
		string(const string& s);

		template <class InputIterator>
		string(InputIterator first, InputIterator last)
		{
			while (first != last)
			{
				push_back(*first);
				++first;
			}
		}
		string& operator=(string tmp);
		//string& operator=(const string& s);

		size_t size() const;
		size_t capacity() const;
		const char* c_str() const;

		bool operator<(const string& s) const;
		bool operator<=(const string& s) const;
		bool operator>(const string& s) const;
		bool operator>=(const string& s) const;
		bool operator==(const string& s) const;
		bool operator!=(const string& s) const;

		const char& operator[](size_t i) const;
		char& operator[](size_t i);

		iterator begin();
		iterator end();

		const_iterator begin() const;
		const_iterator end() const;

		void reserve(size_t n);
		void push_back(char ch);
		void append(const char* str);

		string operator+(const char* str) const;
		string operator+(char ch) const;
		string& operator+=(const char* str);
		string& operator+=(char ch);

		void insert(size_t pos, char ch);
		void insert(size_t pos,const char* str);
		void erase(size_t pos, size_t n = npos);

		size_t find(char ch, size_t pos = 0) const;
		size_t find(const char* sub, size_t pos = 0) const;
		string substr(size_t pos = 0, size_t len = npos) const;
		
		void clear();
		
		void swap(string& s);
		
		~string()
		{
			delete[] _str;
			_capacity = 0;
			_size = 0;
		}
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
	public:
		static const int npos = -1;
	};
	std::ostream& operator<<(std::ostream& os, const string& s);
	std::istream& operator>>(std::istream& is,string& s);
}